<template>
  <div>
    <h2>学校名称：{{ name }}</h2>
    <h2>学校地址：{{ address }}</h2>
    <h1>学生姓名：{{ sname }}</h1>
  </div>
</template>

<script>
// 先在 npm i pubsub-js
import pubsub from "pubsub-js";

export default {
  name: "School",
  data() {
    return {
      name: "HPU",
      address: "河南焦作",
      sname: "",
    };
  },
  mounted() {
    // 谁收谁定义（订阅）
    pubsub.subscribe("hello", function (name, data) {
      console.log("hello回调执行");
      console.log(data);
      // this.sname = data;
    });
  },
};
</script>

<style scoped>
div {
  background: #f40;
  margin: 30px;
}
</style>